package com.sudo.boot.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class SocketClient {
    public static void main(String[] args) throws IOException {
        // 1.连接服务端
        Socket socket = new Socket("localhost", 9090);

        // 2.发送数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("hello, i am client 1".getBytes());
        outputStream.flush();

        // 3.接收服务端返回的数据
        InputStream inputStream = socket.getInputStream();
        byte[] buffer = new byte[1024];
        int lent = inputStream.read(buffer);

        System.out.println("收到服务端消息："+new String(buffer, 0, lent));
        socket.close();
    }
}
